
import java.io.BufferedWriter;
import java.io.FileWriter;
import java.io.IOException;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.Date;

public class Log {
	//private static Log instance = null;
	public static String newline = System.getProperty("line.separator");
	private BufferedWriter logFile;
	DateFormat dateFormat = new SimpleDateFormat("yyyy/MM/dd HH:mm:ss");
	Date date = new Date();
	String dateStr ;

	public Log( String fileName) throws IOException{
		this.logFile = new BufferedWriter(new FileWriter(fileName));
		logFile.write(fileName.substring(0,fileName.indexOf(".")) +" Log file" + newline);
		logFile.write("--------------------------" + newline);
	}

/*	public  Log getInstance(String str) throws IOException{
		if (instance==null)
			instance = new Log(str);
		return instance;
	}
*/
	public void WriteToLog(String event,boolean showTime) throws IOException{
		System.out.println(newline + event);
		dateStr = dateFormat.format(date);
		if (showTime==true)
			logFile.write(newline + dateStr + newline);
		logFile.write( newline + event + newline);
	}

	public void closeLog() throws IOException{
		logFile.close();
	}
}
